//
//  EightDetailTableViewController.m
//  TravelFirst
//
//  Created by lanou3g on 15/9/21.
//  Copyright (c) 2015年 吴娅君. All rights reserved.
//

#import "EightDetailTableViewController.h"
#import "ActHotModel.h"
#import "ActHotTableViewCell.h"
#import "ActDetailViewController.h"

@interface EightDetailTableViewController ()

@property (nonatomic,strong) NSMutableArray *eightArr;

@end

@implementation EightDetailTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.tableView.separatorStyle = 0;
    //隐藏TabBar
    self.navigationController.tabBarController.tabBar.alpha = 0;
    [self jsonAndEight];
    [self.tableView registerClass:[ActHotTableViewCell class] forCellReuseIdentifier:@"eightCell"];
}

//解析8个导航图数据
- (void)jsonAndEight{
    [LORequestManger GET:self.EightUrl success:^(id response) {
        NSDictionary *mdic = (NSDictionary *)response;
        
        for (NSDictionary *dic in mdic[@"activities"]) {
            ActHotModel *model = [[ActHotModel alloc] init];
            [model setValuesForKeysWithDictionary:dic];
            [self.eightArr addObject:model];
        }
        [self.tableView reloadData];
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"%@",error);
    }];
}

//懒加载
- (NSMutableArray *)eightArr{
    if(!_eightArr){
        self.eightArr = [NSMutableArray array];
    }
    return _eightArr;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
//#warning Potentially incomplete method implementation.
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
//#warning Incomplete method implementation.
    // Return the number of rows in the section.
    return self.eightArr.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    ActHotModel *model = self.eightArr[indexPath.row];
    ActHotTableViewCell *cell = [[ActHotTableViewCell alloc] initWithStyle:(UITableViewCellStyleSubtitle) reuseIdentifier:@"eightCell" typeArr:model.tag];
    cell.title.text = model.title;
    cell.city.text = [NSString stringWithFormat:@"%@ - %@",model.city,model.destination];
    cell.time.text = [NSString stringWithFormat:@"%@ 行程%ld天",model.period_desc,model.days];
    cell.Money.text = [NSString stringWithFormat:@"￥%@ - ￥%@",model.min_cost,model.max_cost];
    [cell.logo sd_setImageWithURL:[NSURL URLWithString:model.club[@"logo"]]];
    cell.club.text = model.club[@"title"];
    [cell.picture sd_setImageWithURL:[NSURL URLWithString:model.cover]];
    
    
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 250;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    ActDetailViewController *Controller = [[ActDetailViewController alloc] init];
    ActHotModel *model = self.eightArr[indexPath.row];
    NSString *str = [NSString stringWithFormat:@"http://tubu.ibuzhai.com/rest/v3/activity/%@?access_token=1d209720-f920-497e-8faf-e0e8bc7fbb0a&app_version=2.3.6&device_type=1",model.ID];
    Controller.detailUrl = str;
    Controller.day = model.days;
    [self.navigationController pushViewController:Controller animated:NO];
}

/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
